<template>
  <div class="usage-analyze">
    <a-flex gap="middle">
      <a-card title="存储空间" style="width: 50%">
        <div style="height: 320px; text-align: center">
          <h3>
            {{ formatSize(data.usedSize) }} /
            {{ data.maxSize ? formatSize(data.maxSize) : '无限制' }}
          </h3>
          <a-progress type="dashboard" :percent="data.usageRate ?? 0" />
        </div>
      </a-card>
      <a-card title="图片数量" style="width: 50%">
        <div style="height: 320px; text-align: center">
          <h3>
            {{ data.pictureCount }} /
            {{ data.pictureCapacity ?? '无限制' }}
          </h3>
          <a-progress type="dashboard" :percent="data.usageRate ?? 0" />
        </div>
      </a-card>
    </a-flex>
  </div>
</template>
<script setup lang="ts">
import 'echarts'
import { ref, watchEffect } from 'vue'
import { getSpaceUsageAnalyzeUsingPost } from '@/api/spaceAnalyzeController.ts'
import { message } from 'ant-design-vue'
import { formatSize } from '@/util'

interface Porps {
  queryAll?: boolean
  queryPublic?: boolean
  spaceId?: string
}

const props = withDefaults(defineProps<Porps>(), {
  queryAll: false,
  queryPublic: false,
})
const data = ref<API.SpaceUsageAnalyzeVO>({})
const fetchData = async () => {
  loading.value = true
  try {
    const res = await getSpaceUsageAnalyzeUsingPost({
      queryAll: props.queryAll,
      queryPublic: props.queryPublic,
      spaceId: props.spaceId,
    })
    data.value = res.data
  } catch (e) {
    message.error(e.message)
  } finally {
    loading.value = false
  }
}
const loading = ref(false)
// 加载数据
watchEffect(() => {
  fetchData()
})
</script>

<style scoped></style>
